#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    m_RecordThread = new RecordThread(this);
    ConnectSlots();
    ui->slider_ratio->setEnabled(false);
}

MainWindow::~MainWindow()
{
    delete ui;
    delete m_RecordThread;
}

void MainWindow::ConnectSlots()
{
    connect(m_RecordThread, &RecordThread::recordOver, this, &MainWindow::recordOver, Qt::QueuedConnection);
   // connect(m_RecordThread, SIGNAL(RecordThread::recordOver()), this, SLOT(MainWindow::recordOver()));
    connect(m_RecordThread, &RecordThread::recordPlayOver, this, &MainWindow::recordPlayOver, Qt::QueuedConnection);
    //connect(m_RecordThread, SIGNAL(RecordThread::recordPlayOver()), this, SLOT(MainWindow::recordPlayOver()));
}
void MainWindow::recordOver()
{
    QMessageBox::information(this, "record", "record over");
}

void MainWindow::recordPlayOver()
{
    QMessageBox::information(this, "record play", "record play over");
}

void MainWindow::on_rbtn_tomcat_clicked(bool checked)
{
    m_RecordThread->setType(RecordThread::TOMCAT);
    ui->slider_ratio->setEnabled(false);
}

void MainWindow::on_rbtn_minions_clicked(bool checked)
{
    m_RecordThread->setType(RecordThread::MINIONS);
    ui->slider_ratio->setEnabled(false);
}

void MainWindow::on_slider_ratio_valueChanged(int value)
{
    ui->le_ratio->setText(QString::number(value/1000.0));
    m_RecordThread->setType(RecordThread::NONE);
    m_RecordThread->setPitchShift(value/1000.0);
}

void MainWindow::on_rbtn_none_clicked(bool checked)
{
    ui->slider_ratio->setEnabled(true);
}

void MainWindow::on_btn_close_mic_clicked()
{
    m_RecordThread->stop();
    m_RecordThread->exit(0);
}


void MainWindow::on_btn_open_mic_clicked()
{
    if (m_RecordThread->isRunning())
            m_RecordThread->exit(0);
    m_RecordThread->start();
}

void MainWindow::on_rbtn_realtime_clicked()
{
    m_RecordThread->setPlayType(RecordThread::REALTIME);
}

void MainWindow::on_rbtn_record_clicked()
{
    m_RecordThread->setPlayType(RecordThread::RECORD);
}

void MainWindow::on_btn_record_start_clicked()
{
    m_RecordThread->recordEnable();
}

void MainWindow::on_btn_record_play_clicked()
{
    m_RecordThread->recordEnablePlay();
}
